/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package consumo.session;

import consumo.ejb.BasicSessionBean;
import consumo.entity.Cliente;
import consumo.entity.GrupoClientes;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;

/**
 *
 * @author Carlos Taschetto
 */
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class ClienteSession extends BasicSessionBean {

    public Cliente getById(int id) {
        return getPojo(Cliente.class, id);
    }

    public List<GrupoClientes> getAllClientes(){
        return  getList(GrupoClientes.class, "Select c from GrupoClientes c");
    }
    
    public List<Cliente> getAll(){
        return  getList(Cliente.class, "Select c from Cliente c");
    }

    public Cliente getByNome(String nome){
        return getPojo(Cliente.class, "select c from Cliente c where c.nome like ?1", "%"+nome+"%");
    }


    /**
     * Insere uma nova Concessionaria
     * @param object
     * @return object
     */
    public Cliente save(Cliente object){
        getEm().persist(object);
        return object;
    }
    
    public Cliente set(Cliente object){
        getEm().merge(object);
        return object;
    }
    
    public void remove(Cliente object){
        removeEntity(object);
    }
    
 
}
